<?php 
	$table = 'product';
	$id = $_GET['id'];
	
	$record = $conn -> get_all_data($table,$id);
	$list_catalog = $conn -> get_all_data($table = 'catalog');
	$list_catalog1 = $conn -> get_all_data_fix($table = 'catalog1', -1, 1, $option1 = '  AND catalog_id='.$record['catalog_id']);
?>
<script type="text/javascript">
	$(document).ready(function(){
		$("#news-form").validate({
			rules : {
				catalog : {
					required: true,
				},
				catalog1 : {
					required: true,
				},
				title : {
					required: true,
					maxlength: 255
				},
				price : {
					required: true,
					digits : true,		
				},
				price2 : {
					required: true,
					digits : true,		
				},
				desc : "required",
				content : "required",
				url_image : "required",
														
			},
			messages : {
				catalog : {
					required:  "Hãy chọn danh mục cha",
				},
				catalog1 : {
					required:  "Hãy chọn danh mục cha",
				},
				title : {
					required:  "Hãy nhập tên nhà hàng",
					maxlength: "Giới hạn là 255 kí tự"
				},
				price : {
					required : "Hãy nhập giá",
					digits : "Chỉ nhập số",
				},
				price2 : {
					required : "Hãy nhập giá",
					digits : "Chỉ nhập số",
				},
				desc : "Hãy nhập tóm tắt",
				content : "Hãy nhập nội dung",
				url_image : "Hãy chọn file hình ảnh đại diện",			
			},
			submitHandler: function(form) {
				var path = "ajax/product/edit.php";
				var method = "POST";
				var data = $("#news-form").serialize();
				var content = CKEDITOR.instances.content.getData();
				data += "&content=" + encodeURIComponent(content);
				dashboard.admin.action.edit("news-form", path, method, data, null);
			} 
		});
	});	
</script>
<div id="alert"></div>
<form class="form-horizontal" id="news-form" method="POST">	
	<input type="hidden" value="<?=$record['id']  ?>" name="id" />
	<fieldset>	
		<div class="control-group">
			<label class="control-label">Danh mục</label>
			<div class="controls">
				<select name="catalog" id="catalog" onchange="getCatalog()">
					<option value="" >----Chọn danh mục cha-----</option>
					<?php foreach ($list_catalog as $key => $value): ?>
						<option value="<?=$value['id']  ?>" <?=$value['id'] == $record['catalog_id'] ? "selected='selected'":""  ?> ><?=$value['title']  ?></option>
					<?php endforeach ?>
				</select>
			</div>
		</div>
		<script type="text/javascript">
            function getCatalog(){
                var catalog_id = $('#catalog :selected').val();
				$("#catalog1").load("ajax/business.php?p=catalog&a=list_c1&id="+catalog_id);
            }
        </script>
		<div class="control-group">
			<label class="control-label">Danh mục cấp 2</label>
			<div class="controls">
				<select name="catalog1" id="catalog1">
					<option value="" >----Chọn danh mục con-----</option>
					<?php foreach ($list_catalog1 as $key => $value): ?>
						<option value="<?=$value['id']  ?>" <?=$value['id'] == $record['catalog1_id'] ? "selected='selected'":""  ?> ><?=$value['title']  ?></option>
					<?php endforeach ?>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">Tiêu đề</label>
			<div class="controls">
				<input type="text" id="title" class="input-xlarge" value="<?=$record['title']  ?>" name="title" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">Mô tả</label>
			<div class="controls">
				<input type="text" id="desc" class="input-xlarge" value="<?=$record['description']  ?>" name="desc" />
			</div>
		</div>	
		<div class="control-group">
			<label class="control-label">Giá</label>
			<div class="controls">
				<input type="text" id="price" class="input-xlarge" value="<?=$record['price']  ?>" name="price" />
			</div>
		</div>	
		<div class="control-group">
			<label class="control-label">Giá giảm</label>
			<div class="controls">
				<input type="text" id="price2" class="input-xlarge" value="<?=$record['price2']  ?>" name="price2" />
				<span class="help-inline">Mặc định là 0</span>
			</div>
		</div>	
		<div class="control-group">
			<label class="control-label">Tên file ảnh tại gallery</label>
			<div class="controls">
				<input type="text" class="input-xlarge" value="<?=$record['url_image']  ?>" name="url_image" id="url_image" />
				<input type="button" value="Chọn file" id="btnChonFile" name="btnChonFile" onclick="BrowseServer('Images:/','url_image')">
			</div>
		</div>	
		<div class="control-group">
			<label class="control-label">Nội dung</label>
			<div class="controls">
				<textarea id="content" class="wysiwyg"   rows="15" cols="30">
					<?=$record['content']  ?>
				</textarea>						
			</div>
		</div>	
		<div class="form-actions">
			<button class="btn btn-primary" name="submit" value="submit" type="submit">Save changes</button>
			<a href="javascript:void(0)" onclick="javascript:history.go(-1);" class="btn">Cancel</a>
		</div>
	</fieldset>
</form>